package com.education.platform.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.education.platform.entity.Conversation;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 会话Mapper接口
 *
 * @author education-platform
 * @since 2024-10-07
 */
@Mapper
public interface ConversationMapper extends BaseMapper<Conversation> {

    /**
     * 分页查询用户会话列表
     */
    IPage<Conversation> selectUserConversationPage(Page<Conversation> page, @Param("userId") Long userId);

    /**
     * 查询用户会话列表
     */
    List<Conversation> selectUserConversations(@Param("userId") Long userId);

    /**
     * 根据参与者查询私聊会话
     */
    Conversation selectPrivateConversation(@Param("user1Id") Long user1Id, @Param("user2Id") Long user2Id);

    /**
     * 更新会话最后消息信息
     */
    void updateLastMessage(@Param("conversationId") String conversationId, 
                          @Param("messageId") Long messageId,
                          @Param("messageContent") String messageContent);

    /**
     * 查询会话参与者
     */
    List<Long> selectParticipants(@Param("conversationId") String conversationId);

    /**
     * 检查用户是否为会话参与者
     */
    boolean isParticipant(@Param("conversationId") String conversationId, @Param("userId") Long userId);
}
